<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.utils.SiteHelper" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.util.List" %>
<%@ page import="com.qipay.baas.model.*" %>
<!doctype html>
<html>
<head>
    <jsp:include page="head.jsp"></jsp:include>
    <title>编辑支付渠道信息</title>
</head>
<body class="devpreview hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <% CpChannel cpChannel = (CpChannel) request.getAttribute("detail");
            boolean isAdd = String.valueOf(request.getAttribute("isadd")).equals("1");
            User currentUser = (User) session.getAttribute("user");
            UserLevel userLevel = SiteHelper.getUserLevelByLevel(currentUser.getLevel());
            CpInfo cpInfo = (CpInfo) request.getAttribute("detailInfo");
            Cp cp = (Cp) request.getAttribute("detailCp");
            Boolean isHaveProxy = false;
            Boolean isProxy = cp.getType() == 2;
            long proxyId = 0;
            Cp cpAgent = (Cp) request.getAttribute("detailCpParent");
            List<ChannelType> channelTypes = (List<ChannelType>)request.getAttribute("channelTypes");
            if (cpAgent != null) {
                isHaveProxy = true;
            }
            List<CpChannel> agentChannels = (List<CpChannel>) request.getAttribute("agentChannels");

        %>
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box box-info">
                        <% if (request.getParameter("error") != null) {%>
                        <div class="alert alert-error">
                            <%if(request.getParameter("error").endsWith("1")){%>
                            商户的手续费要高于代理商的手续费
                            <%}%>
                            <%if(request.getParameter("error").endsWith("2")){%>
                            此商户的渠道已存在，只能有一种支付渠道
                            <%}%>
                        </div>
                        <%}%>

                        <!-- /.box-header -->
                        <!-- form start -->
                        <form class="form-horizontal" action="save" method="POST" id="doc-vld-msg">
                            <input type="hidden" name="cpId" value="<%= isAdd?cpInfo.getCpId():cpChannel.getCpId()%>">
                            <input type="hidden" name="id" value="<%= isAdd?"":String.valueOf(cpChannel.getId())%>">
                            <div class="box-body" id="dvContent">
                                <div class="form-group">
                                    <label for="txtfeeRecharge" class="col-sm-2 control-label">当前编辑的企业：</label>
                                    <div class="col-sm-10">
                                        <%= cpInfo.getName()%>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="ddltype" class="col-sm-2 control-label">支付方式：</label>
                                    <div class="col-sm-10">
                                        <select id="ddltype" name="channelType">
                                            <% if(agentChannels!=null&&agentChannels.size()>0){ for(CpChannel agentChannel: agentChannels){%>
                                            <option value="<%=agentChannel.getChannelType()%>"><%= SiteHelper.getChannelTypeString(agentChannel.getChannelType())%>
                                            </option>
                                            <%}}else{%>
                                            <% for (ChannelType channelType:channelTypes) {%>
                                            <option value="<%= channelType.getId()%>"><%= channelType.getName()%></option>
                                            <%}}%>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group" >
                                    <label for="txtfeeRecharge" class="col-sm-2 control-label">费率(%)：</label>
                                    <div class="col-sm-10" style="display:<%= isAdd?"":"none"%>">
                                        <span class="help-block">商户支付费率统一采用默认费率</span>
                                    </div>
                                    <div class="col-sm-10" style="display:<%= isAdd?"none":""%>">
                                        <input type="number"  class="form-control" id="txtfeeRecharge" name="feeRecharge"
                                               mush="1"
                                               value="<%= isAdd?"10":cpChannel.getFeeRecharge()%>" placeholder="费率">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="ddlState" class="col-sm-2 control-label">状态：</label>
                                    <div class="col-sm-10">
                                        <select id="ddlState" name="state">
                                            <option value="0"><%= SiteHelper.getChannelStateString((byte) 0)%>
                                            </option>
                                            <option value="1"><%= SiteHelper.getChannelStateString((byte) 1)%>
                                            </option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <!-- /.box-body -->
                            <div class="box-footer">
                                <button type="button" class="btn btn-primary btn-sm borderNone"
                                        onclick="window.history.back()">返回</button>
                                <button type="button" class="btn btn-success btn-sm borderNone" id="btnSearch">确 定</button>
                            </div>
                            <!-- /.box-footer -->
                        </form>
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <%--<jsp:include page="foot.jsp"></jsp:include>--%>
</div>
<script type="text/javascript"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>
    $(function () {
        var isAddnow = '<%= request.getAttribute("isadd")%>',
            currentType = parseInt("<%= cpChannel !=null&&cpChannel.getChannelType()!=null?cpChannel.getChannelType().byteValue():0%>", 10),
            channelState = parseInt("<%= cpChannel !=null&&cpChannel.getState()!=null?cpChannel.getState().byteValue():0%>", 10);
        if (isAddnow == "1") {
            currentType = "0";
        }
        else {
            currentType = "<%= cpChannel !=null&&cpChannel.getChannelType()!=null?cpChannel.getChannelType().byteValue():1%>";
        }
        if (currentType > 0) {
            $("#ddltype").val(currentType);
        }
        if (channelState > 0) {
            $("#ddlState").val(channelState);
        }
        $("#btnSearch").on("click", function () {
            var isGo = checkInputMust("dvContent");
            if (isGo) {
                var recharge = parseInt($("#txtfeeRecharge").val(), 10);
                if (recharge < 0 || recharge > 100) {
                    alert("支付费率值要在0-100之间");
                    return;
                }
                $("#doc-vld-msg")[0].submit();
            }
        });
    });
</script>
</body>
</html>

